package com.example.myapplication.fragment;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.example.myapplication.Iocn;
import com.example.myapplication.MyAdapter;
import com.example.myapplication.R;
import com.example.myapplication.lunbo.LooperPageAdapter;

import java.util.ArrayList;
import java.util.List;


public class MyFragment1 extends Fragment {

    private Context mContext;
    private GridView mGridView;
    private BaseAdapter mAdapter = null;
    private ArrayList<Iocn> mData = null;
    private ViewPager mLoopPager;
    private LooperPageAdapter mLooperPageAdapter;
    private List<Integer> sPics = new ArrayList<>();


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.activity_main, container, false);
        mGridView = (GridView) view.findViewById(R.id.gridview);
        mLoopPager=(ViewPager)view.findViewById(R.id.looper_paper);
//        Log.e("HEHE", "1日狗");
//
        mData = new ArrayList<>();
        mData.add(new Iocn(R.drawable.phone, "手机"));
        mData.add(new Iocn(R.drawable.book, "笔记本"));
        mData.add(new Iocn(R.drawable.ping, "平板"));
        mData.add(new Iocn(R.drawable.watch, "智能手表"));
        mData.add(new Iocn(R.drawable.peper, "居家百货"));
        mData.add(new Iocn(R.drawable.richang, "生活日常"));
        mData.add(new Iocn(R.drawable.quan, "大额好券"));
        mData.add(new Iocn(R.drawable.all, "全部分类"));

        mAdapter = new MyAdapter<Iocn>(mData, R.layout.gridview_item) {
            @Override
            public void bindView(ViewHolder holder, Iocn obj) {
                holder.setImageResource(R.id.img, obj.getiID());
                holder.setText(R.id.text, obj.getiName());
            }
        };
        mGridView.setAdapter(mAdapter);
        mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(mContext, "你点击了~" + position + "~项", Toast.LENGTH_SHORT).show();
            }
        });
//        GridView gridview = (GridView) findViewById(R.id.gridview);
//        ArrayList<HashMap<String, Object>> meumList = new ArrayList<HashMap<String, Object>>();
//        for (int i=1;i<9;i++){
//            HashMap<String,Object> map=new HashMap<>();
//            map.put("ItemImage",R.drawable.phone);
//            map.put("ItemText",""+i);
//            meumList.add(map);
//        }
//        SimpleAdapter simpleAdapter=new SimpleAdapter(this,
//                meumList,
//                R.layout.gridview_item,
//                new String[]{"ItemImage","ItemText"},
//                new int[]{R.id.img,R.id.text}
//                );
//        gridview.setAdapter(simpleAdapter);
//    }
        sPics.add(R.drawable.banner);
        sPics.add(R.drawable.banner);
        sPics.add(R.drawable.banner);


        //设置适配器
        mLooperPageAdapter = new LooperPageAdapter();
        mLooperPageAdapter.setData(sPics);
        mLoopPager.setAdapter(mLooperPageAdapter);

        return view;
    }
}